/**
 * JAVACC DEMO 1.0
 */
package com.apache.info.service.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.info.manager.InfoReleaseManager;

import java.util.Map;

/**
 * description:  动态获取信息列表
 *
 * @author Hou Dayu 创建时间：2016-8-29
 */
public class SelectDynamicInfoPluginImpl extends AbstractInfoReleasePlugin {

    private InfoReleaseManager InfoReleaseManager;

    /**
     * TODO 动态获取信息列表插件实现.
     *
     * @see com.apache.info.service.plugins.AbstractInfoReleasePlugin#doInvoke(ParamsVo)
     */
    protected Object doInvoke(ParamsVo vo) {
        Map<String, String> map = (Map) vo.getParams("params");
        String pageIndex = Validator.getDefaultStr(map.get("pageIndex"), "0");
        String pageSize = Validator.getDefaultStr(map.get("pageSize"), "0");
        if ("0".equals(pageIndex) || "0".equals(pageSize)) {
            return InfoReleaseManager.getList(vo);
        } else {
            vo.setParams("pageIndex", pageIndex);
            vo.setParams("pageSize", pageSize);
            return InfoReleaseManager.getPageInfo(vo);
        }
    }

    public void setInfoReleaseManager(InfoReleaseManager infoReleaseManager) {
        InfoReleaseManager = infoReleaseManager;
    }

}
